package com.hgkj.cloud.customer.common;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;

public class FileSaver {

	private MultipartFile file;
	private File localFile;
	public FileSaver(MultipartFile file) {
		this.file = file;
	}
	public FileSaver(File file) {
		this.localFile = file;
	}
	
	//获取扩展名
	public String getExtension() {
		return "."+FilenameUtils.getExtension(file.getOriginalFilename());
	}
	
	public void saveFile(File file) throws IllegalStateException, IOException {
		this.file.transferTo(file);
	}
	
	public String getExtensionOpen() {
		return "."+FilenameUtils.getExtension(localFile.getName());
	}
	public void saveFileOpen(File file) {
		try {
			FileUtils.copyFile(this.localFile, file);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public MultipartFile getFile() {
		return file;
	}

	public void setFile(MultipartFile file) {
		this.file = file;
	}

	public File getLocalFile() {
		return localFile;
	}

	public void setLocalFile(File localFile) {
		this.localFile = localFile;
	}
}
